package com.situying.hibernate.test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

/**
 * 
 */

/**
 * @author ysitu
 *
 */
public class InsertDerby {
	private static String driver = "org.apache.derby.jdbc.EmbeddedDriver";
	private static String database = "jdbc:derby:derbyDB";
	
	public static void main(String[] args) {
		try {
			Class.forName(driver);
			Properties prop = new Properties();
			prop.put("user", "user1");
			prop.put("password", "user1");
			Connection conn = DriverManager.getConnection(database,prop);
			conn.setAutoCommit(false);
			Statement stat = conn.createStatement();
//			stat.execute("create table book(book_id int, book_name varchar(80), author varchar(80),primary key(book_id))");
//			
//			PreparedStatement ps = conn.prepareStatement("insert into book values(?,?,?)");
//			ps.setInt(1, 1);
//			ps.setString(2, "HuangRan Collection");
//			ps.setString(3, "Lu Xun");
//			ps.executeUpdate();
//			
//			ps.setInt(1, 2);
//			ps.setString(2, "The Sad Travel Of Culture");
//			ps.setString(3, "Yu QiuYu");
//			ps.executeUpdate();
//			
//			ps.setInt(1, 3);
//			ps.setString(2, "Trible Doors");
//			ps.setString(3, "Han Han");
//			ps.executeUpdate();
//			
//			stat.execute("create table book_order(serial_number int, book_id int, client_id int, book_date timestamp,primary key(serial_number),constraint fk_book_id foreign key (book_id) references book(book_id))");
//			stat.execute("alter table book_order add constraint fk_client_id foreign key (client_id) references client(client_id)");
			ResultSet rs = stat.executeQuery("select * from client");
			while(rs.next())
			{
				System.out.println(rs.getString("CLIENT_ID")+":"+rs.getString("CLIENT_NAME"));
			}
			conn.commit();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
